//
//  login.swift
//  PerfectTemplate
//
//  Created by Master on 2017/1/13.
//
//

import Foundation
import PerfectLib
import PerfectHTTP


class message: NSObject {
    func regist(_ request: HTTPRequest, response: HTTPResponse) -> Void {
        let d: [String:Any] = ["result":"success", "resultCode":1,"data":[ "Bool": true, "meessage":[2, 4, 5, 7, 8]]]
        
        do {
            try response.setBody(json: d)
        } catch {
            
        }
        response.completed()
    }
    
    func login(_ request: HTTPRequest, response: HTTPResponse) -> Void {
        response.setBody(string: "登陆成功")
        response.completed()
    }
    func score(_ request: HTTPRequest, response: HTTPResponse) -> Void {
        let scoreArray: [String:Any] = ["result": "success", "resultCode": 1, "data": [
            "top":100,"mid":200,"bottom":50
            ]
            ]
        do {
            try response.setBody(json: scoreArray)
        } catch  {
            print("fail")
        }
        response.completed()
    }
    func getData(_ request: HTTPRequest, response: HTTPResponse) -> Void {
        let request = baseRequest()
        let urlString = "http://www.weather.com.cn/data/cityinfo/101010100.html"
      request.getData(urlString: urlString, success: { (responseData) in

        let dic:[String : Any] = responseData as! [String : Any]
        let josn = try? dic.jsonEncodedString()
        response.setBody(string: josn!)
        response.completed()
//             print("获取数据:\(josn)")
      }) { (NSError) in
        
        }

        
    }

}
